package com.heimali.happyreader;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;

public class SplashyActivity extends Activity implements OnClickListener {

	private static final int DELAYED = 2000;

	private Button loginBtn;
	private Button browseBtn;
	private ImageButton startBtn;

	private boolean isLogin = false;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		isLogin = Statics.isLogin();
		initView();
		new Handler().postDelayed(new Runnable() {
			public void run() {
				if (isLogin) {
					start();
				}
			}
		}, DELAYED);
	}

	private void initView() {
		setContentView(R.layout.splashy);
		browseBtn = (Button) findViewById(R.id.browse_btn);
		loginBtn = (Button) findViewById(R.id.login_btn);
		startBtn = (ImageButton) findViewById(R.id.start_btn);
		browseBtn.setOnClickListener(this);
		loginBtn.setOnClickListener(this);
		startBtn.setOnClickListener(this);
	}

	private void start() {
		Intent intent = new Intent();
		if (isLogin) {
			intent.setClass(this, ArticleListActivity.class);
		} else {
			intent.setClass(this, LoginActivity.class);
		}
		startActivity(intent);
		finish();
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.browse_btn:
			startActivity(new Intent(this, ArticleListActivity.class));
			finish();
			break;
		case R.id.login_btn:
			startActivity(new Intent(this, LoginActivity.class));
			finish();
			break;
		case R.id.start_btn:
			start();
			break;
		default:
			break;
		}

	}
}
